# -*- coding: utf-8 -*-

import wx
import sys
import wx.html as html

from webbrowser import open_new
from threading import Thread

#from Cheetah.Template import Template

class MyHtmlWindow(html.HtmlWindow):
    def __init__(self, parent, id):
        html.HtmlWindow.__init__(self, parent, id, size=(400, 300))
        self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)

    def OnScroll(self, event):
        event.Skip()
        
    def OnLinkClicked(self, linkinfo):
        try:
            Thread(target = open_new(linkinfo.GetHref())).start()
        except:
            print "exception"

class MyHtmlDialog(wx.Dialog):
    def __init__(self, parent, title, content):
        wx.Dialog.__init__(self, parent, -1, title)
        
        btn = wx.Button(self, wx.ID_OK, " OK ")
        btn.SetDefault()
        
        color = self.GetBackgroundColour()
        bgcolor = "#%02x%02x%02x" % (color.Red(), color.Green(), color.Blue())
        
        about_html = "<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD>" + \
                     "<BODY BGCOLOR=" + bgcolor + " TEXT=#000000>" + \
                     content + \
                     "</BODY></HTML>"
        
        #print about_html.encode('utf8')
        self.html = MyHtmlWindow(self, -1)
        self.html.SetPage(about_html)
        
        buttonbox = wx.BoxSizer(wx.HORIZONTAL)
        buttonbox.Add(btn, 0, wx.ALL, 5)

        outerbox = wx.BoxSizer(wx.VERTICAL)
        outerbox.Add(self.html, 0, wx.EXPAND|wx.ALL, 5)
        outerbox.Add(buttonbox, 0, wx.ALIGN_CENTER)
       
        self.SetAutoLayout(True)
        self.SetSizer(outerbox)
        self.Fit()
        
        
class About(MyHtmlDialog):
    def __init__(self, parent):

        self.parent = parent
        #self.utility = parent.utility
        
        bittornado_version = "0.3.13"
        py2exe_version = "0.6.2"
        nsis_version = "2.16"
                
        title = "MetaGen" #self.utility.lang.get('aboutabc')

#        # Start UI in Dialog
#        #######################
#        
#        btn = wx.Button(self, wx.ID_OK, " OK ")
#        btn.SetDefault()
#        
#        color = self.GetBackgroundColour()
#        bgcolor = "#%02x%02x%02x" % (color.Red(), color.Green(), color.Blue())

        wx_version = str(wx.MAJOR_VERSION) + "." + str(wx.MINOR_VERSION) + "." + str(wx.RELEASE_NUMBER)
        
        major, minor, micro, releaselevel, serial = sys.version_info
        python_version = str(major) + "." + str(minor) + "." + str(micro)




        content =  u"""
          <p>
            <CENTER>
              <b>Ideagen<BR>
              0.1        </b>
            </CENTER>
           </p>

      <FONT SIZE=-1>
      <P>
      <TABLE BORDER=0 CELLSPACING=0>
        <TR>
          <TD>作者:</TD>
          <TD>马建军(mjj@163.com)</TD>
        </TR>
        <TR>
          <TD>日期:</TD>
          <TD>2007.12.9</TD>
        </TR>
        <TR>
          <TD>主页:</TD>
          <TD><A HREF="http://www.aideasoft.com">http://www.aideasoft.com</A></TD>
        </TR>
      </TABLE>
      <P>特别感谢:<BR>
        <BR>梁志海
        <BR>
        <BR>
        及其他支持Metagen的朋友！
      <P>Powered by 
      <A HREF="http://www.python.org>Python 2.4.4"</A>, 
      <A HREF="http://www.wxpython.org">wxPython 2.6.4</A>, 
      <A href="">NSIS 2.16</A>
      <P>Copyright (c) 2007-2008, Aideasoft
      </FONT>       
        """
        
        """
        self.var="mjj"
        filename = "%about.html"   
        nameSpace = {'usernames':self.var} 
        sp = Template(file="about.html", searchList=[nameSpace])
        content = "%s"%(sp)
        """
        MyHtmlDialog.__init__(self, parent, title, content)        
